package cn.whao.guli.order.config;

import cn.whao.guli.order.rule.MyRandomRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * ClassName: MyAutoConfig
 * Package: cn.whao.guli.order.config
 * Description:
 *
 * @Author 王豪
 * @Create 2024/11/26 17:08
 * @Version 1.0
 */
@Configuration
public class RibbonConfig {

    // 向容器中添加轮询策略对象覆盖默认的
    @Bean
    public RandomRule randomRule() {
//        return new RandomRule();  // 随机的轮询策略
        return new MyRandomRule();  // 自定义的随机的轮询策略
    }

    @LoadBalanced  // 使用Ribbon的负载均衡对RestTemplate进行增强
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}
